class ValidPalindrome:
    def isPalindrome(self, s: str):
        raise NotImplementedError

class solution1(ValidPalindrome):
    def isPalindrome(self, s: str):
        sgoods = "".join(ch.lower() for ch in s if ch.isalnum())
        return sgoods == sgoods[::-1]

class solution2(ValidPalindrome):
    def isPalindrome(self, s: str):
        sgoods = "".join(ch.lower() for ch in s if ch.isalnum())
        n = len(s)
        left, right = 0, n - 1
        while left < right:
            if sgoods[left].lower() != sgoods[right].lower():
                return False
            left, right = left + 1, right - 1
        return True

class Solution3(ValidPalindrome):
    def isPalindrome(self, s: str):
        n = len(s)
        left, right = 0, n - 1
        while left < right:
            while left < right and not s[left].isalnum():
                left += 1
            while left < right and not s[right].isalnum():
                right -= 1
            if s[left].lower() != s[right].lower():
                return False
            left, right = left + 1, right - 1
        return True
